<template>
  <view class="my-userinfo-container">
    <!-- 头像/名称区域 -->
    <view class="top-box">
      <image :src="userinfo.avatarUrl" class="avatar"></image>
      <view class="nickname">{{ userinfo.nickName }}</view>
    </view>
    <!-- 面板区域 -->
    <view class="panel-list">
      <!-- 第一个面板 -->
      <view class="panel">
        <view class="panle-body">
          <view class="panle-itme">
            <text>8</text>
            <text>收藏的店铺</text>
          </view>
          <view class="panle-itme">
            <text>14</text>
            <text>收藏的商品</text>
          </view>
          <view class="panle-itme">
            <text>18</text>
            <text>关注的商品</text>
          </view>
          <view class="panle-itme">
            <text>84</text>
            <text>足迹</text>
          </view>
        </view>
      </view>
      <!-- 第二个面板 -->
      <view class="second">
        <view class="my-orders"><text>我的订单</text></view>
        <view class="second-body">
          <view class="body-item">
            <uni-icons type="color" size="40" color="#c00000"></uni-icons>
            <text>待付款</text>
          </view>
          <view class="body-item">
            <uni-icons type="wallet" size="40" color="#c00000"></uni-icons>
            <text>待收货</text>
          </view>
          <view class="body-item">
            <uni-icons
              type="refreshempty"
              size="40"
              color="#c00000"
            ></uni-icons>
            <text>退款/退货</text>
          </view>
          <view class="body-item">
            <uni-icons type="eye" size="40" color="#c00000"></uni-icons>
            <text>全部订单</text>
          </view>
        </view>
      </view>
      <!-- 第三面板 -->
      <view class="third-panel">
        <view class="item">
          <text>收货地址</text>
          <uni-icons type="forward"></uni-icons>
        </view>
        <view class="item">
          <text>联系客服</text>
          <uni-icons type="forward"></uni-icons>
        </view>
        <view class="item" @click="logout">
          <text>退出登录</text>
          <uni-icons type="forward"></uni-icons>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapState } from 'vuex';
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState('user', ['userinfo'])
  },
  methods: {
    async logout() {
      const [err, succ] = await uni
        .showModal({
          title: '提示',
          content: '确定要退出登录吗？'
        })
        .catch(err => err);
      if (succ && succ.confirm) {
        this.$store.commit('user/saveUser', {});
        this.$store.commit('user/updateUserInfo', {});
        this.$store.commit('user/saveToken', '');
      }
    }
  }
};
</script>

<style lang="scss">
.my-userinfo-container {
  height: 100%;
  background-color: #f4f4f4;
  .top-box {
    height: 400rpx;
    background-color: #c00000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .avatar {
      width: 90px;
      height: 90px;
      border-radius: 45px;
      border: 1px solid #fff;
      box-shadow: 0px 1px 5px black;
    }
    .nickname {
      font-size: 16px;
      color: #fff;
      font-weight: bold;
      margin-top: 10px;
    }
  }
  .panel-list {
    padding: 0px 10px;
    .panel {
      background-color: #fff;
      border-radius: 5px;
      transform: translateY(-10px);
      .panle-body {
        display: flex;
        justify-content: space-around;
        .panle-itme {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          align-items: center;
          font-size: 13px;
          padding: 10px 0px;
        }
      }
    }
  }
  .second {
    border-radius: 5px;
    background-color: #fff;
    margin-bottom: 10px;
    .my-orders {
      padding: 10px 0px 10px 10px;
      border-bottom: 1px solid #efefef;
    }
    .second-body {
      display: flex;
      justify-content: space-around;
      padding: 10px 0;
      .body-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        color: #c00000;
      }
    }
  }
  .third-panel {
    border-radius: 5px;
    background-color: #fff;
    .item {
      display: flex;
      justify-content: space-between;
      padding: 15px;
      border-bottom: 1px solid #efefef;
    }
    .item:nth-child(3) {
      display: flex;
      justify-content: space-between;
      padding: 15px;
    }
  }
}
</style>
